package hzjbbis.framework.util.dao;


import hzjbbis.framework.util.Resources;

import java.sql.Connection;

import junit.framework.TestCase;

/**
 * @author lix
 */
public class ConnectionManagerTest extends TestCase {
	private ConnectionManager cm = null;
	/**
	 * Constructor for ConnectionManagerTest.
	 * @param arg0
	 */
	public ConnectionManagerTest(String arg0) {
		super(arg0);
	}
	/**
	 * @see TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
		cm = ConnectionManager.getInstance();
	}

	/**
	 * @see TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testGetInstance() {
		String cmClassName = Resources.getString("cmClassName");
		//System.out.println("--" + cmClassName + "--");
		assertNotNull(cm);
		assertEquals(cmClassName, cm.getClass().getName());
	}

	public void testGetConnection() {
		try {
			Connection con = cm.getConnection();
			assertNotNull(con);
			assertFalse(con.isClosed());
			cm.close1(con);
		} catch (Exception e) {
			e.printStackTrace();
			fail();
		}
	}

	/*
	 * Test for void close(Connection)
	 */
	public void testCloseConnection() {
		try {
			Connection con = cm.getConnection();
			cm.close1(con);
			assertTrue(con.isClosed());
		}catch (Exception e) {
			e.printStackTrace();
			fail();
		}
	}

}
